package org.ala.tiktools.generator.mybatis.creator.dao;

import org.ala.tiktools.generator.mybatis.config.info.Part;
import org.ala.tiktools.generator.mybatis.creator.entity.EntityInfo;
import org.ala.tiktools.generator.mybatis.creator.entity.fields.EntityFieldsInfo;
import org.ala.tiktools.generator.mybatis.creator.order_by.OrderByInfo;
import org.ala.tiktools.generator.mybatis.creator.query.QueryInfo;
import org.ala.tiktools.generator.mybatis.dbinfo.TableInfo;
import org.ala.tiktools.generator.mybatis.tools.Tools;

import java.util.HashSet;
import java.util.Set;

/**
 * 生成dao类需要的信息
 * - findAll()
 * - findByQuery(Query query)
 * - count()
 * - countByQuery(Query query)
 * - findByPage(Pager pager, Query query)
 *
 * - insert(Entity entity)
 * - batchInsert(List<Entity> entities)
 *
 * - update(Query query, Entity entity)
 * - multipleUpdate(List<MultipleUpdate> multipleUpdates)
 *
 * - delete(Query query)
 * - multipleDelete(List<Query> queries)
 *
 * @author ala
 * @date 2024-12-31 15:21
 */
public class DaoInfo {

    protected EntityInfo e;
    protected EntityFieldsInfo fe;
    protected QueryInfo q;
    protected TableInfo t;
    protected OrderByInfo ob;

    protected String className;
    protected String pkg;
    protected Set<String> imports = new HashSet<>();
    protected String mutileUpdate, mutileUpdateName;
    /**
     *  mapper注解
     */
    protected String annotation;
    protected String annotationName;


    public static DaoInfo build(Part p, TableInfo t, EntityInfo e, QueryInfo q, OrderByInfo ob, EntityFieldsInfo fe) {
        DaoInfo d = new DaoInfo();
        d.e = e; d.q = q; d.t = t; d.ob = ob; d.fe = fe;

        d.pkg = p.getOut().getDao().getPkg();
        d.annotation = p.getOut().getDao().getAnnotation();
        String[] ss = d.annotation.split("\\.");
        d.annotationName = ss[ss.length-1];
        d.className = Tools.lowToUpFirst(Tools.hump(t.getName())) + p.getOut().getDao().getSuffix();
        d.mutileUpdate = p.getOut().getDao().getMutileUpdate();
        ss = d.mutileUpdate.split("\\.");
        d.mutileUpdateName = ss[ss.length-1];

        d.imports.add("java.util.List");
        d.imports.add(e.getPkg() + "." + e.getClassName());
        d.imports.add(q.getPkg() + "." + q.getClassName());
        d.imports.add(fe.getPkg() + "." + fe.getClassName());
        d.imports.add(p.getOut().getDao().getAnnotation());
        d.imports.add(p.getOut().getDao().getPagement());
        d.imports.add(p.getOut().getDao().getPager());
        d.imports.add(d.ob.getPkg() + "." + d.ob.getClassName());
        d.imports.add(d.annotation);
        d.imports.add(d.mutileUpdate);

        return d;
    }

    public EntityInfo getE() {
        return e;
    }

    public void setE(EntityInfo e) {
        this.e = e;
    }

    public QueryInfo getQ() {
        return q;
    }

    public void setQ(QueryInfo q) {
        this.q = q;
    }

    public TableInfo getT() {
        return t;
    }

    public void setT(TableInfo t) {
        this.t = t;
    }

    public String getClassName() {
        return className;
    }

    public void setClassName(String className) {
        this.className = className;
    }

    public String getPkg() {
        return pkg;
    }

    public void setPkg(String pkg) {
        this.pkg = pkg;
    }

    public Set<String> getImports() {
        return imports;
    }

    public void setImports(Set<String> imports) {
        this.imports = imports;
    }

    public String getAnnotation() {
        return annotation;
    }

    public void setAnnotation(String annotation) {
        this.annotation = annotation;
    }

    public String getAnnotationName() {
        return annotationName;
    }

    public void setAnnotationName(String annotationName) {
        this.annotationName = annotationName;
    }

    public String getMutileUpdate() {
        return mutileUpdate;
    }

    public void setMutileUpdate(String mutileUpdate) {
        this.mutileUpdate = mutileUpdate;
    }

    public OrderByInfo getOb() {
        return ob;
    }

    public void setOb(OrderByInfo ob) {
        this.ob = ob;
    }

    public String getMutileUpdateName() {
        return mutileUpdateName;
    }

    public void setMutileUpdateName(String mutileUpdateName) {
        this.mutileUpdateName = mutileUpdateName;
    }

    public EntityFieldsInfo getFe() {
        return fe;
    }

    public void setFe(EntityFieldsInfo fe) {
        this.fe = fe;
    }
}
